// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <pollux/expression/cast_expr.h>
#include <pollux/type/simple_function_api.h>
#include <pollux/type/type.h>

namespace kumo::pollux {
    class GeometryType : public VarbinaryType {
        GeometryType() = default;

    public:
        static const std::shared_ptr<const GeometryType> &get() {
            static const std::shared_ptr<const GeometryType> instance{
                new GeometryType()
            };
            return instance;
        }

        bool equivalent(const Type &other) const override {
            // Pointer comparison works since this type is a singleton.
            return this == &other;
        }

        const char *name() const override {
            return "GEOMETRY";
        }

        std::string toString() const override {
            return name();
        }

        melon::Dynamic serialize() const override {
            melon::Dynamic obj = melon::Dynamic::object;
            obj["name"] = "Type";
            obj["type"] = name();
            return obj;
        }
    };

    MELON_ALWAYS_INLINE bool isGeometryType(const TypePtr &type) {
        // Pointer comparison works since this type is a singleton.
        return GeometryType::get() == type;
    }

    MELON_ALWAYS_INLINE std::shared_ptr<const GeometryType> GEOMETRY() {
        return GeometryType::get();
    }

    // Type used for function registration.
    struct GeometryT {
        using type = Varbinary;
        static constexpr const char *typeName = "geometry";
    };

    using Geometry = CustomType<GeometryT>;
} // namespace kumo::pollux
